package com.clickpaas.workinghours.service.Impl;

import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.d20210220155135.model.CampaignDTO;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.d20210220155135.model.CampaignDTOPageInfoResponse;
import com.bizcloud.ipaas.tbba4bf83484b4ed2aacba581fbfeac4d.d20210220155135.model.CampaignDTOResponse;
import com.clickpaas.workinghours.dao.CampaignDao;
import com.clickpaas.workinghours.entity.CampaignEntity;
import com.clickpaas.workinghours.service.CampaignService;
import com.clickpaas.workinghours.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class CampaignServiceImpl implements CampaignService {
    @Resource
    private CampaignDao campaignDao;

    /**
     * 获取数据
     *
     * @param entity
     * @return
     */
    @Override
    public List<CampaignDTO> getDataInfo(CampaignEntity entity) {
        List<CampaignDTO> reList = new ArrayList<>();
        try {
            if (null == entity || DataInfoUtil.isAllFieldNull(entity)){
                reList = DataInfoUtil.castListCopy(campaignDao.queryDataInfo(),CampaignDTOPageInfoResponse.class,CampaignDTO.class);
            }else {
                reList = DataInfoUtil.castListCopy(campaignDao.queryDataInfo(entity),CampaignDTOResponse.class,CampaignDTO.class);
            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",entity,e);
            return null;
        }
        if (null != reList && reList.size()>0){
            return reList;
        }
        return null;
    }

    /**
     * 项目数据转换为bean
     *
     * @param list
     * @return
     */
    @Override
    public List<CampaignEntity> DataConver(List<CampaignDTO> list) {
        return DataInfoUtil.castListCopy(list,CampaignDTO.class,CampaignEntity.class);
    }
}
